/* default for NSObject is to externally increment the ref count;
subclasses may redefine if they have their own reference counting scheme, but should not call super;
For convenience only, retain returns self; no other object should be returned than self */
- (oneway void)release;
/* default for NSObject is to externally decrement the reference count and to perform dealloc if zero;
subclasses may redefine if they have their own reference counting scheme, but should not call super */
- autorelease;
/* Inserts the object in the current delayed free pool, and returns the object itself for convenience;
*/
- (unsigned)retainCount;
/* Method that should only be used for DEBUG or very unusual ref-counting strategies!
default for NSObject is to return the externally maintained ref count;
subclasses may should override this method if they implement their own refcounting scheme.
This method is only used by foundation during debug, when "enableDoubleFreeCheck" (or the dwrite NSDisableDoubleFreeCheck) has been set to check for overfreeing, or over autoreleasing of objects.
For objects which never get released (i.e. their release method is a no-op), this method should return UINT_MAX. */
@end
@protocol NSCopying
- copyWithZone:(NSZone *)zone;
/* expresses snapshots of objects.
Typical usage is for 'passing by value' value objects. The only guarantee of the snapshot operation for classes that implement the NSCopying protocol is that:
-copyWithZone: will yield a functional object as long as you don't change the returned value.
That snapshot operation does not preserve class mutability (for classes for which that makes sense). Immutability of the returned value is not guaranteed in general either, although Property List classes (NSString, NSData, NSArray, NSDictionary) guarantee immutable returned values.
This method is an exception to the allocation rule: returned value is owned by caller who is responsible for releasing it;
zone may be NULL */
- copy;
/* Shortcut for copyWithZone: using the default zone;
must be defined as: return [self copyWithZone:NULL]; */
@end
@protocol NSMutableCopying
- mutableCopyWithZone:(NSZone *)zone;
/* This should be implemented by cluster of classes that differentiate between mutable and immutable objects (such as the basic property list classes)
It should yield a mutable copy, owned by the caller;
zone may be NULL */
- mutableCopy;
/* Shortcut for mutableCopyWithZone: using the default zone;
must be defined as: return [self mutableCopyWithZone:NULL]; */
@end
@protocol NSCoding
/* The NSCoding protocol is implemented by objects that wish to be persistent and/or distributed */
- (void)encodeWithCoder:(NSCoder *)aCoder;
/* Object should store its state onto aCoder;
First thing should be to call [super encodeWithCoder:];
Default for NSObject is to encode nothing */
- initWithCoder:(NSCoder *)aDecoder;
/* Called with a freshly allocated object;
should ask its super to reestablish its state, and then fill itself with data obtained from aDecoder;
When the exact format of the parent classes serialization is known, the object can replace itself by another object. In that case, -initWithCoder: must deallocate self, and take total responsability of the deserialization. Also, there is a restriction that the original object must not appear more than once in the encoding graph;
Default for NSObject is to do nothing */
@end
/*********** Base class ***********/
@interface NSObject <NSObject, NSCoding> {
Class isa;
}
+ initialize;
+ load;
- init;
- (void)dealloc;
/* deallocates self;
subclasses should release their instance variables and call [super dealloc] */
/* Allows argument to propose another object at its place when encoding;
nil means to encode nothing;
default is to return self */
- awakeAfterUsingCoder:(NSCoder *)aDecoder;
/* Gives a last change for the object to propose another at its place;
This is necessary because an object (say an instance of a subclass Font) may decide to replace itself once all the -initWithCoder have been done, and the method deciding to replace maybe in the middle of the inheritance hierarchy (say Font).
Default is simply to return self;
If a replacement takes place, the implementation of -awakeAfterUsingCoder is responsible for releasing the old self */
/* Increments an externally maintained 'extra reference count' for object;
The first reference (typically done in the +alloc method) is NOT maintained externally (=> no need to call NSIncrementExtraRefCount for that first allocation) */
/* Decrements the externally maintained reference count if there is one (and returns NO) else returns YES;
Typical idiom in the -release method is:
if (NSDecrementExtraRefCountWasZero(self)) [self dealloc];
*/
/*********** Misc *******/
/* NSComparisonResult is used for ordered comparision results. If the first argument to the comparision (the receiving object in a message call or the left argument in a function call) is greater than the second, NSOrderedDescending is returned. If it is smaller, NSOrderedAscending is returned. Examples: